using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using EntityLayer;
using BusinessLayer;

public partial class Admin_searchParameters : SFPage
{
    entSearchParameters insEntSearchParameters = new entSearchParameters();
    busSearchParameters insBusSearchParameters = new busSearchParameters();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool sfgSearchParameters_NeedsDataSource()
    {
        busSearchParameters insBusSearchParameters = new busSearchParameters();
        DataTable insDataTableSearchParameters = insBusSearchParameters.SelectSearchParameters();
        if (insBusSearchParameters.HasErrors)
        {
            MessageBoxShow(insBusSearchParameters);
            return false;
        }

        sfgSearchParameters.SetData(insDataTableSearchParameters);
        return false;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        this.Id = 0;
        this.OpenEditPanel();
    }
    protected void sfgSearchParameters_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditData")
        {
            this.Id = Convert.ToInt32(e.CommandArgument);
            this.OpenEditPanel();
        }
        else if (e.CommandName == "DeleteData")
        {
            insEntSearchParameters.SearchParameterId = Convert.ToInt32(e.CommandArgument);
            insBusSearchParameters.DeleteSearchParametersBySearchParameterId(insEntSearchParameters);
            if (insBusSearchParameters.HasErrors)
            {
                MessageBoxShow(insBusSearchParameters);
                return;
            }
            sfgSearchParameters.LoadGridData();
            this.CloseEditPanel();
        }
    }
    public override void OpenEditPanel()
    {
        this.Clear(this.Master.FindControl("ContentPlaceHolderEdit"));
        base.OpenEditPanel();
        FillEditPanel();
    }
    private void FillEditPanel()
    {
        if (this.Id != 0)
        {
            insEntSearchParameters.SearchParameterId = this.Id;
            insBusSearchParameters.SelectSearchParametersBySearchParameterId(insEntSearchParameters);
            txtResultType.Text = insEntSearchParameters.ResultType;
            txtSearchDescription.Text = insEntSearchParameters.SearchDescription;
            txtSearchPoint.Value = insEntSearchParameters.SearchPoint;
            txtSearchResultAddress.Text = insEntSearchParameters.SearchResultAddress;
        }
        else
        {
            txtResultType.Text = "";
            txtSearchDescription.Text = "";
            txtSearchPoint.Clear();
            txtSearchResultAddress.Text = "";
        }
    }

    public override void Save()
    {
        this.Validate();
        if (this.HasErrors)
        {
            MessageBoxShow(this);
            return;
        }
        insEntSearchParameters.ResultType = txtResultType.Text;
         insEntSearchParameters.SearchDescription=txtSearchDescription.Text;
        insEntSearchParameters.SearchPoint=txtSearchPoint.Value.Value ;
        insEntSearchParameters.SearchResultAddress=txtSearchResultAddress.Text ;
        base.Save();
    }
    public override void SaveNew()
    {
        insBusSearchParameters.InsertSearchParameters(insEntSearchParameters);
        if (insBusSearchParameters.HasErrors)
        {
            MessageBoxShow(insBusSearchParameters);
            return;
        }
        base.SaveNew();
        sfgSearchParameters.LoadGridData();
    }
    public override void SaveExisting()
    {
        insEntSearchParameters.SearchParameterId = this.Id;
        insBusSearchParameters.UpdateSearchParametersBySearchParameterId(insEntSearchParameters);
        if (insBusSearchParameters.HasErrors)
        {
            MessageBoxShow(insBusSearchParameters);
            return;
        }
        base.SaveExisting();
        sfgSearchParameters.LoadGridData();
    }
}
